<?php

declare(strict_types=1);

return [
    'mode' => SWOOLE_PROCESS,
    'http' => [
        'ip'        => '0.0.0.0',
        'port'      => 9501,
        'sock_type' => SWOOLE_SOCK_TCP,
        'callbacks' => [
//            'request' => [\App\Events\HTTP::class, 'onRequest'],
            'task'    => [\App\Events\HTTP::class, 'onTask'],
            'finish'  => [\App\Events\HTTP::class, 'onFinish'],
        ],
        'process'   => [
//            [\App\Process\TestProcess::class, 'handle']
        ],
        'settings'  => [
            'worker_num'         => 8,
            'task_worker_num'    => 6,
//            'daemonize'          => true,
            'log_file'           => BASE_PATH . '/swoole.log',
            'pid_file'           => BASE_PATH . '/server.pid',
            'buffer_input_size'  => 2 * 1024 * 1024,
            'buffer_output_size' => 32 * 1024 * 1024,
            'package_max_length' => 2 * 1024 * 1024,
        ],
    ],
    'ws'   => [
        'ip'        => '0.0.0.0',
        'port'      => 9502,
        'sock_type' => SWOOLE_SOCK_TCP,
        'callbacks' => [
            "open"    => [\App\Events\WebSocket::class, 'onOpen'],
            "message" => [\App\Events\WebSocket::class, 'onMessage'],
            "close"   => [\App\Events\WebSocket::class, 'onClose'],
        ],
        'settings'  => [
            'worker_num'              => swoole_cpu_num(),
            'open_websocket_protocol' => true,
            'daemonize'               => true,
            'log_file'                => BASE_PATH . '/swoole.log',
            'pid_file'                => BASE_PATH . '/server.pid',
            'buffer_input_size'       => 2 * 1024 * 1024,
            'buffer_output_size'      => 32 * 1024 * 1024
        ],
    ],

    // 主服务
    'main' => [
        'ip'         => '0.0.0.0',
        'port'       => 9501,
        'mode'       => SWOOLE_BASE, // 不填默认为SWOOLE_PROCESS
        'sock_type'  => SWOOLE_SOCK_TCP,
        'class_name' => \Swoole\Http\Server::class,
        'callbacks'  => [
            'request' => [\App\Events\Http::class, 'onRequest'],
        ],
        'process'    => [
        ],
        'settings'   => [
            'worker_num' => swoole_cpu_num(),
            'pid_file'   => BASE_PATH . '/main.pid',
        ],
        // 子服务 可以多个
        'sub'        => [
            [
                'ip'        => '0.0.0.0',
                'port'      => 9502,
                'sock_type' => SWOOLE_SOCK_TCP,
                'callbacks' => [
                    'receive' => [\App\Events\Tcp::class, 'onReceive'],
                    'close'   => [\App\Events\Tcp::class, 'onClose'],
                ],
                'settings'  => [
                    'open_http_protocol' => false, // 设置这个端口关闭HTTP协议功能
                ]
            ],
        ]
    ],
];
